<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%--
  Created by IntelliJ IDEA.
  User: 29513
  Date: 2021/5/7
  Time: 9:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%
        //获取项目的根路径
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    %>
    <meta charset="utf-8">
    <title>患者队列查询</title>

    <!-- jquery -->
    <script type="text/javascript" src="<%=basePath%>static/jquery/jquery-1.12.4.js"></script>

    <link rel="stylesheet" href="<%=basePath%>static/swee/sweetalert.css">

    <script src="<%=basePath%>static/swee/sweetalert-dev.js"></script>

    <link rel="stylesheet" href="<%=basePath%>static/layui-v2.6.5/layui/css/layui.css">

    <script type="text/javascript" src="<%=basePath%>static/layui-v2.6.5/layui/layui.js"></script>

    <script src="<%=basePath%>static/doctor/js/check.js" type="text/javascript"></script>

    <link rel="stylesheet" href="<%=basePath%>static/doctor/css/check.css">

    <meta name="renderer" content="webkit">

    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

</head>

<body>


<div style="height: 50px"></div>

<%--候诊队列--%>
<div class="checkqueue">

    <div class="layui-form">

        <%--        <form action="<%=basePath%>doctorg/selPatient" method="post">--%>
        <%--            <input type="text" name="name" lay-verify="email" autocomplete="off" class="name">--%>
        <%--            <button type="submit" id="select" class="layui-btn layui-btn-radius" name="nameselect">查询</button>--%>

        <%--            <button type="submit" id="selectall" class="layui-btn layui-btn-radius" name="selectall" value="selectall">--%>
        <%--                记录--%>
        <%--            </button>--%>
        <%--        </form>--%>

        <table class="layui-table" lay-skin="row">
            <colgroup>
                <col width="150">
                <col width="150">
                <col width="200">
                <col>
            </colgroup>
            <thead>
            <tr>
                <th>序号</th>
                <th>诊断号</th>
                <th>名字</th>
                <th>操作</th>
            </tr>
            </thead>

            <tbody class="bangding">

            <c:forEach items="${page.list}" var="list">
                <tr>
                    <td>${list.id}</td>
                    <td>${list.patientId}</td>
                    <td>${list.patientName}</td>

                    <c:if test="${list.state==0}">
                        <td>
                            <button type="button" id="ok" class="layui-btn layui-btn-radius">确认问诊</button>
                        </td>
                    </c:if>
                </tr>
            </c:forEach>

            </tbody>
        </table>

    </div>
</div>

<%--检查队列--%>
<div class="checkduiwu">
    <div id="big">
        <table class="layui-table" lay-skin="line">
            <colgroup>
                <col width="150">
                <col width="150">
                <col width="200">
                <col>
            </colgroup>
            <thead>
            <tr>
                <th>病人编号</th>
                <th>病人姓名</th>
                <th>状态</th>
            </tr>
            </thead>
            <tbody id="tbody">
            <c:forEach items="${pat.list}" var="pat">
                <tr>
                    <td>${pat.patientId}</td>
                    <td>${pat.patientName}</td>
                    <td>问诊中</td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </div>
</div>

<%--开具检查单--%>
<div class="checkdan">

    <h3 style="">检查单</h3>
    <form class="layui-form" action="" style="background-color: white;">
        <div class="layui-inline">
            <label class="layui-form-label">诊断号:</label>
            <div class="layui-input-inline">
                <input type="tel" name="" autocomplete="off" class="layui-input" readonly>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">姓名:</label>
            <div class="layui-input-inline">
                <input type="text" name="" autocomplete="off" class="layui-input" readonly>
            </div>
        </div>
        <br><br>
        <label class="layui-form-label">检查项目</label>
        <div class="layui-input-inline">
            <select name="modules" lay-verify="required" lay-search="">
                <option value="0">CT</option>
                <option value="1">和磁共振</option>
                <option value="2">B超</option>
                <option value="3">心电图</option>
                <option value="4">常规检查</option>
            </select>
        </div>
    </form>
    <button data-method="offset" data-type="auto" class="layui-btn layui-btn-sm" id="checkok">确认</button>

</div>

<%--个人详细信息--%>
<div class="info">

    <%--    处方笺--%>
    <div class="chufanginfo">
        <p id="docid" style="display: none">${sessionScope.doctor.doctorId}</p>
        <p id="docname" style="display: none">${sessionScope.doctor.doctorName}</p>
        <div class="yaodann">
            <h1 style="color:#009f95;">华子医院</h1>
            <h3 style="color:#009f95;">门诊处方笺</h3>
            <br>
            <form action="">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">诊断号:</label>
                        <div class="layui-input-inline">
                            <input type="tel" name="" autocomplete="off" class="layui-input"
                                   style="border: none;border-bottom: 1px solid #009f95;" readonly>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">姓名:</label>
                        <div class="layui-input-inline">
                            <input type="text" name="" autocomplete="off" class="layui-input"
                                   style="border: none;border-bottom: 1px solid #009f95;" readonly>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">医生:</label>
                        <div class="layui-input-inline">
                            <input type="tel" id="doctor" autocomplete="off" class="layui-input"
                                   style="border: none;border-bottom: 1px solid #009f95;" readonly>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">时间:</label>
                        <div class="layui-input-inline">
                            <input type="text" id="myclock" autocomplete="off" class="layui-input"
                                   style="border: none;border-bottom: 1px solid #009f95;" readonly>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">诊断结果:</label>
                        <div class="layui-input-inline">
                            <input type="text" name="" id="bingli" autocomplete="off" class="layui-input"
                                   style="width:300px ;border: none;border-bottom: 1px solid #009f95;">
                        </div>
                    </div>
                </div>

                <div id="wz" style="background-color: white;">
                    <div id="test7" class="demo-transfer" style="margin-left: 20px" class="wezhi"></div>
                    <div class="layui-btn-containesumr" style="margin-left: 20px" class="wezhi">
                        <button type="button" class="" lay-demotransferactive="getData" id="suoding"></button>
                        <button type="button" class="layui-btn" lay-demotransferactive="getData" id="n">√</button>
                        <button type="button" class="layui-btn" lay-demotransferactive="reload" id="sousuo">搜索药品
                        </button>
                    </div>
                </div>

                <button type="button" class="layui-btn" id="drugok">确认开药</button>
                <div class="drugshow"></div>
                <div class="sum">
                    <p class="drugdan" style="font-size: 15px">
                        药品号<span STYLE="margin-left: 80px;"></span>
                        药品名<span STYLE="margin-left: 90px;"></span>
                        数量<span STYLE="margin-left: 80px;"></span>剂量</p>
                </div>
            </form>
        </div>
    </div>


    <%--    右侧边盒子--%>
    <div class="checktype">

        <div class="check-bingli">
            <p style="width: 50px; color: #0bc9be;font-size: 20px; margin: auto;">病史</p>
            <div class="binglich">
                <table class="layui-table" lay-skin="line">
                    <tr>
                        <th>病例</th>
                        <th>患病时间</th>
                    </tr>
                </table>
            </div>

        </div>

        <div class="check-ct">
            <p style="width: 100px; color: #0bc9be;font-size: 20px; margin: auto;">检查记录</p>
            <div class="ctch">
                <table class="layui-table" lay-skin="line">
                    <tr>
                        <th>部位</th>
                        <th>结果</th>
                        <th>时间</th>
                    </tr>
                </table>
            </div>
        </div>


        <%--操作--%>
        <div class="cz">
            <a href="<%=basePath%>doctorc/selMedicine?doctorId=${sessionScope.doctor.doctorId}&userName=<%=request.getAttribute("doctorname")%>">
                <button type="button" class="layui-btn" lay-demotransferactive="getData" id="drugrecord">药单</button>
            </a>
            <a href="<%=basePath%>doctorh/index">
                <button type="button" class="layui-btn">患者详情</button>
            </a>
        </div>

        <%--主诉--%>
        <div class="zhusu">
            <p style="color: #0bc9be;font-size: 20px;width: 60px;margin: auto">主诉：</p>
            <textarea cols="40" rows="4"></textarea>
        </div>

    </div>


    <script type="text/javascript">
        show()

        function show() {
            $.ajax({
                url: "<%=basePath%>doctorh/drug",
                type: "post",
                dateType: "json",
                success: function (data) {
                    layui.use(['transfer', 'layer', 'util'], function () {
                        var $ = layui.$
                            , transfer = layui.transfer
                            , layer = layui.layer
                            , util = layui.util;
                        //获得数据库所有药的数据
                        //基础效果
                        //实例调用
                        transfer.render({
                            elem: '#test7'
                            , data: data
                            , id: 'key123' //定义唯一索引
                        })
                        //批量办法定事件
                        util.event('lay-demoTransferActive', {
                            getData: function (othis) {

                                getDataa = transfer.getData('key123'); //获取右侧数据

                                $(function () {

                                    var count = 0;

                                    for (var i in getDataa) {
                                        count++;
                                    }

                                    for (i = 0; i < count; i++) {
                                        $(".drugdan").after("<p class=" + "xunhuan" + "><span>" +
                                            getDataa[i].value + "</span><span>" + getDataa[i].title + "</span><span></span><input type='text' value='5'>盒" + "" +
                                            " <input type='text' id='yizhu' value='每日3片' style='margin-left: 80px;border: none;border-bottom: 1px solid #e3e2e2 '  ></p>")
                                    }

                                })
                            }
                            , reload: function () {
                                //实例重载
                                transfer.reload('key123', {
                                    title: ['药库', '开药']
                                    , value: []
                                    , showSearch: true
                                })
                            }
                        });
                    });
                }
            })
        }

    </script>
    <script type="text/javascript">


        $("#ctDiv").hide();//隐藏CT结果
        $("#DisDiv").hide();//隐藏以往病例
        $("#open").hide();//隐藏开药盒子

        $(function () {
            $(".ct").click(function () {
                $(this).addClass("layui-btn layui-btn-disabled");
                $("#big").css({"opacity": "0.2", "background-color": "#a9a9a9"});
            })
            $(".bl").click(function () {
                $(this).addClass("layui-btn layui-btn-disabled");
                $("#big").css({"opacity": "0.2"});
            })
            $("#CtClose").click(function () {
                $("#ctDiv").hide();
                $(".ct").removeClass("layui-btn-disabled");
                $("#ctDiv tbody").find("tr").remove();
                $("#big").css({"opacity": "1"});
            })
            $("#DisClose").click(function () {
                $("#DisDiv").hide();
                $(".bl").removeClass("layui-btn-disabled");
                $("#DisDiv tbody").find("tr").remove();
                $("#big").css({"opacity": "1"});
            })


            $("#tbody").on("click", "#kaiyao", function () {
                $(".yaodand").show()
                $(".yaodan").show()
                $(".drugdan~p").remove();

                // 获得所有开药框所有的节点
                for (var i = 0, j = 1; i < 4; i++, j++) {

                    $(".layui-form-item input:eq(" + i + ")").val($(this).parent().parent().parent().children("td:eq(" + j + ")").text())
                }
                $(".layui-form-item input:eq(3)").val("")

            })
            // 确认开药
            $("#drugok").click(function () {
                //获取 诊断号
                var id = $(".layui-form-item input:eq(0)").val()
                //获取 姓名
                var name = $(".layui-form-item input:eq(1)").val()
                //获取 医生
                var doctorId = $("#docid").text()
                //获取 时间
                var time = $(".layui-form-item input:eq(3)").val()
                //得到药品长度
                var len = $(".drugdan~p").length;


                var drugid = new Array();
                var drugsum = new Array();
                var drugtype = new Array();
                //获取节点的药品 数量 医嘱等信息
                var arrlist = $(".drugdan~p")

                for (var i = 0; i < len; i++) {
                    drugid[i] = $(arrlist[i]).children("span:eq(0)").text()
                    drugsum[i] = $(arrlist[i]).children("input:eq(0)").val()
                    drugtype[i] = $(arrlist[i]).children("input:eq(1)").val()
                }
                let strid = drugid.join("-");
                let strsum = drugsum.join("-");
                let strtype = drugtype.join("-");

                if ($("#bingli").val() == null || $("#bingli").val() == "") {
                    swal("请输入诊断结果", "", "success");
                    return
                }
                $.ajax({
                    url: "http://localhost:8080/doctorh/kaiyao",
                    type: "post",
                    data: {
                        id: id,
                        name: name,
                        doctorId: doctorId,
                        time: time,
                        drugid: strid,
                        drugsum: strsum,
                        drugtype: strtype,
                        bingli: $("#bingli").val()
                    },
                    dateType: "json",
                    success: function (data) {
                        swal("开药成功", "", "success");
                        setInterval(function () {
                            window.location.replace("http://localhost:8080/doctorg/selPatient?doctorId=${sessionScope.doctor.doctorId}");
                        }, 1000);

                    }
                })

            })
            $("#drugno").click(function () {
                $(".yaodand").hide()
                $(".yaodan").hide()
                $(".drugdan~p").remove();
            })

            //检查
            $("#tbody").on("click", "#cheneck", function () {
                $(".checkqueue,.bccheckqueue").show()
                $(".checkqueue input:eq(0)").val($(this).parent().parent().parent().children("td:eq(1)").text())
                $(".checkqueue input:eq(1)").val($(this).parent().parent().parent().children("td:eq(2)").text())
            })
            //确定检查
            $("#checkok").click(function () {

                $.ajax({
                    url: "http://localhost:8080/doctorh/inspect", //请求路径
                    type: "post", //请求方式
                    data: {
                        id: $(".checkdan input:eq(0)").val()
                    },//请求参数
                    dataType: "json",//数据格式
                    success: function (data) {
                        if (data == false) {
                            swal("检查单已开，通知患者去检查")
                        } else {
                            swal("请不要重复开检查单")
                        }
                    }
                })
            })

        })


        function dispttime() {
            var today = new Date();
            var yearr = today.getFullYear();
            var moth = today.getMonth();
            var ri = today.getDate();
            var hh = today.getHours()
            var mm = today.getMinutes()
            var ss = today.getSeconds();
            var sh = "";
            if (hh < 12) {
                sh = "AM"
            } else {
                sh = "PM"
            }
            if (hh > 12) {
                hh = hh - 12
            }

            document.getElementById("myclock").value = yearr + "/" + (moth + 1) + "/" + ri + "/" + hh + ":" + mm + ":" + ss

        }

        setInterval("dispttime()", 1000)

    </script>

</body>
</html>
